<?php
    session_start();
	$idAnuncio=$_REQUEST['identificadorAnuncio'];
	
	include("TableDataGateway/TDGGenerarEstadisticas.php");
	include("grafico.php");
	$TDG = new TDGGenerarEstadisticas();
	$grafico=new Grafico();
	$generado=0;
	
	if($idAnuncio!=NULL){
		$visitas = $TDG->recuperarVisitas($idAnuncio);
		$num_rows = mysql_num_rows($visitas);
		$puntos=array();
		$fechas=array();
		while($row = mysql_fetch_array($visitas)){
			array_push($puntos, $row[0]);
			array_push($fechas, $row[1]);
		}
		if($puntos[0]!=null){
			$generado=1;
			$grafico->crearGrafico($puntos,$fechas);
		}
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>Vitamina U</title>
        <meta name="keywords" content="itinerary, list" />
        <meta name="description" content="This page provides a list of all itineraries" />
        <link href="css/default.css" rel="stylesheet" type="text/css" />
		
		<script type="text/javascript">			
			function test() {
				//var elTableRow = document.getElementById("0").value;
				//var elTableCells = elTableRow.getElementsByTagName("td");
				//alert(elTableCells[0].innerText);
				//alert(document.forms[0].getElementsByTagId("0").v);
				//alert("Putaaaaaaaaaa");
				//alert(document.getElementById('Usuarios').rows[0].cells[0].data);
				alert(document.getElementById("0").innerText);
			}
		</script>
    </head>
    
    
    <body>
		<div id="wrapper">
        <?php include 'include/header2.php'; ?>
            <!-- end div#header -->
            <div id="page2">
                <div id="content">
                    <div id="welcome">
					<center><h1>Generar Estad&iacute;sticas</h1>
					 <!-- <form id="form_datos" action="administrarhistorico.php" method="POST">
						<input type="submit" name="Historico" id="Historico"  value="Ver Historico"/>
						<input type="submit" name="Activo" id="Activo"  value="Ver Activos"/>
					</form>-->
					</center>
					<?php
						$result = $TDG->recuperarAnuncios();
						IF($result){
							echo "<center><table border = '0'> \n";
							echo "<tr> \n";
							echo "<th><font color=#AA2808><center><b>Nombre</b></center></font></th> \n";
							//echo "<td><b>ID</b></td> \n";
							echo "</tr> \n";
							while ($row = mysql_fetch_row($result)){
								echo "<tr> \n";
								echo "<FORM METHOD='POST' ACTION='generarestadisticas.php'>";
								echo "<td>$row[0]</td> \n";
								//echo "<td>$row[1]</td> \n";
								echo "<input type='hidden' name='identificadorAnuncio' id='identificadorAnuncio' value='$row[1]'>";
								echo "<td><input class='form_submitb' type='submit' value='Generar' ></td> \n";
								echo "</FORM>";
								echo "</tr> \n";
							}
							echo "</table></center> \n";
						}
						
						if($idAnuncio!=NULL){
							if($generado!=0){
								header ("Location: mostrarGrafico.php");
							}
						}
					?>
					
					
                    </div>	
                </div>
				
				<div id="sidebar">

                </div>

                <div style="clear: both; height: 1px"></div>
            </div>
			<?php
			/*if($idAnuncio!=NULL){
				if($generado!=0){
					ECHO "</BR></BR><div style='background: white'> <center><IMG SRC='grafico.png' BORDER=0 BGCOLOR=#FFFFFF WIDTH=640 HEIGHT=210 ></center></div>";
				}
			}*/
			?>
			
            <?php include 'include/footer2.php'; ?>

        </div>
        <!-- end div#wrapper -->
    </body>
</html>